package com.yigerende.controller;

import com.yigerende.pojo.Account;
import com.yigerende.service.AdminService;
import com.yigerende.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private UserService userService;

    @GetMapping("login/{username}/{password}/{type}")
    public Account login(@PathVariable("username") String username,@PathVariable("password") String password,@PathVariable("type") String type){
        Account account = new Account();
        //判断登录的是用户还是管理员
        if(type.equals("user")){
            account = userService.login(username,password);
        }
        if(type.equals("admin")){
            account = adminService.login(username,password);
        }
        return account;
    }
}
